"use strict";
const electron = require("electron");
electron.contextBridge.exposeInMainWorld("electronAPI", {
  // Chrome窗口相关
  getChromeWindows: () => electron.ipcRenderer.invoke("get-chrome-windows"),
  getRunningChromeWindows: () => electron.ipcRenderer.invoke("get-running-chrome-windows"),
  closeChromeWindow: (windowId) => electron.ipcRenderer.invoke("close-chrome-window", windowId),
  closeRunningChromeWindow: (windowId, pid) => electron.ipcRenderer.invoke("close-running-chrome-window", windowId, pid),
  launchChromeProfile: (windowId) => electron.ipcRenderer.invoke("launch-chrome-profile", windowId),
  launchChrome: (options) => electron.ipcRenderer.invoke("launch-chrome", options),
  // 屏幕相关
  getScreens: () => electron.ipcRenderer.invoke("get-screens"),
  // 窗口排列相关
  arrangeWindows: (params) => electron.ipcRenderer.invoke("arrange-windows", params),
  // 任务队列相关
  addLaunchTask: (args) => electron.ipcRenderer.invoke("add-launch-task", args),
  addCloseTask: (args) => electron.ipcRenderer.invoke("add-close-task", args),
  addArrangeTask: (args) => electron.ipcRenderer.invoke("add-arrange-task", args),
  getTaskStatus: (taskId) => electron.ipcRenderer.invoke("get-task-status", taskId),
  getAllTasks: () => electron.ipcRenderer.invoke("get-all-tasks"),
  // 同步控制相关
  startSync: (windowIds) => electron.ipcRenderer.invoke("start-sync", windowIds),
  stopSync: () => electron.ipcRenderer.invoke("stop-sync"),
  // 文件系统相关
  createShortcut: (options) => electron.ipcRenderer.invoke("create-shortcut", options),
  selectChromeExecutable: () => electron.ipcRenderer.invoke("select-chrome-executable"),
  selectDirectory: () => electron.ipcRenderer.invoke("select-directory"),
  // 环境创建相关
  createChromeEnvironment: (config) => electron.ipcRenderer.invoke("create-chrome-environment", config),
  // 系统相关
  checkAdminPermission: () => electron.ipcRenderer.invoke("check-admin-permission"),
  restartAsAdmin: () => electron.ipcRenderer.invoke("restart-as-admin"),
  quitApp: () => electron.ipcRenderer.invoke("quit-app"),
  // 设置相关
  getSettings: () => electron.ipcRenderer.invoke("get-settings"),
  saveSettings: (settings) => electron.ipcRenderer.invoke("save-settings", settings),
  // 路径相关
  getDefaultPaths: () => electron.ipcRenderer.invoke("get-default-paths")
});
electron.contextBridge.exposeInMainWorld("electronEvents", {
  onSyncStatusChange: (callback) => {
    electron.ipcRenderer.on("sync-status-change", (event, status) => callback(status));
    return () => electron.ipcRenderer.removeAllListeners("sync-status-change");
  },
  onWindowCreated: (callback) => {
    electron.ipcRenderer.on("window-created", (event, windowInfo) => callback(windowInfo));
    return () => electron.ipcRenderer.removeAllListeners("window-created");
  }
});
